//
//  LGSchedulSettingCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/2/28.
//

#import "LGSchedulSettingCell.h"

@interface LGSchedulSettingCell()

/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *timeLabel;
/**   */
@property (nonatomic , strong)UILabel *numberLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;
/**   */
@property (nonatomic , strong)UILabel *weekLabel;
/**   */
@property (nonatomic , strong)NSDictionary *weekDic;

@end

@implementation LGSchedulSettingCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.weekDic = @{@"0":@"周日",@"1":@"周一",@"2":@"周二",@"3":@"周三",@"4":@"周四",@"5":@"周五",@"6":@"周六"};
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.timeLabel.text = LGNSString(dataDic[@"time"]);
    self.numberLabel.text = [NSString stringWithFormat:@"每日 %@ 人",dataDic[@"total"]];
    NSArray *weekArray = dataDic[@"week_days"];
    NSString *weekDay = @"";
    if(weekArray.count == 7){
        weekDay = @"每日";
    }else{
        for (NSInteger i=0; i<weekArray.count; i++) {
            NSString *key = LGNSString(weekArray[i]);
            weekDay = (weekDay.length>0)?[NSString stringWithFormat:@"%@ %@",weekDay,self.weekDic[key]]:self.weekDic[key];
        }
    }
    self.weekLabel.text = weekDay;
}

-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    self.contentView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self.contentView addSubview:self.baseView];
    [self.contentView addSubview:self.timeLabel];
    [self.contentView addSubview:self.numberLabel];
    [self.contentView addSubview:self.tipView];
    [self.contentView addSubview:self.weekLabel];
    [self.contentView addSubview:self.lineView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(self.contentView).offset(viewPix(16));
        make.top.right.equalTo(self.contentView).offset(-viewPix(16));
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(28));
        make.right.equalTo(self.contentView).offset(-viewPix(28));
        make.bottom.equalTo(self.contentView);
        make.height.equalTo(@(0.5));
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _timeLabel.frame = CGRectMake(viewPix(29), viewPix(10), viewPix(150), viewPix(22));
    }
    return _timeLabel;
}

-(UILabel *)numberLabel{
    if(!_numberLabel){
        _numberLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentRight lines:1];
        _numberLabel.frame = CGRectMake(Screen_W-viewPix(140), viewPix(12), viewPix(100), viewPix(22));
    }
    return _numberLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip12"]];
        _tipView.frame = CGRectMake(Screen_W-viewPix(40), viewPix(17), viewPix(12), viewPix(12));
    }
    return _tipView;
}

-(UILabel *)weekLabel{
    if(!_weekLabel){
        _weekLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
        _weekLabel.frame = CGRectMake(viewPix(28), kMaxY(self.timeLabel.frame)+viewPix(4), Screen_W-viewPix(75), viewPix(22));
    }
    return _weekLabel;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E8E8E8"];
    }
    return _lineView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
